﻿using System;
using Entities.DataBase.Persistent;

namespace Entities.DataBase.Obj {

    public class ProductUpdator {

        public string  Name        { get; set; }
        public string  Cname       { get; set; }
        public string  Keywords    { get; set; }
        public string  Description { get; set; }
        public double  Postage       { get; set; }
        public double  Weight     { get; set; }
        public string  WeightUnit { get; set; }
        public int?    Stock      { get; set; }
        public int?    ListOrder  { get; set; }
        public bool    Enabled    { get; set; }

        public ProductUpdator() {
            Stock = null;
        }

        public void UpdateProduct(Product product) {
            product.DateUpdated = DateTime.UtcNow;
            if (!string.IsNullOrEmpty(Name) && !product.Name.Equals(Name)) {
                product.Name = Name;
            }

            if (!string.IsNullOrEmpty(Cname) && !product.CName.Equals(Cname)) {
                product.CName = Cname;
            }

            if (!string.IsNullOrEmpty(Keywords) && !product.Keywords.Equals(Keywords)) {
                product.Keywords = Keywords;
            }

            if (!string.IsNullOrEmpty(WeightUnit) && !product.WeightUnit.Equals(WeightUnit)) {
                 product.WeightUnit = WeightUnit;
            }

            if (Math.Abs(Postage - 0.0) > 0) {
                product.Postage = (decimal)Postage;
            }

            if (Math.Abs(Weight - 0.0) > 0) {
                product.Weight = Weight;
            }

            if (ListOrder != null) {
                product.ListOrder = (int) ListOrder;
            }

        }
    }
}